package sis.studentinfo;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-07-28 18:51
 * @notify
 * @version 1.0
 */

import java.io.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

//将课程 保存到本地.
public class CourseCatalog {
    //课程集合
    private List<Session> sessions = new ArrayList<>();

    //添加课程
    public void add(Session session) {
        sessions.add(session);
    }

    //获取全部课程
    public List<Session> getSessions() {
        return sessions;
    }

    //清除课程
    public void clearAll() {
        sessions.clear();
    }

    //下载到本地
    public void store(String fileName) throws IOException {
        ObjectOutputStream output = null;
        try {
            output = new ObjectOutputStream(new FileOutputStream(fileName));
            output.writeObject(sessions);
        } finally {
            {
                output.close();
            }
        }
    }

    //从本地还原
    public void load(String fileName) throws Exception {
        ObjectInputStream input = null;
        try {
            input = new ObjectInputStream(new FileInputStream(fileName));
            sessions = (List<Session>) input.readObject();
        } finally {
            input.close();
        }
    }
}
